import request from '@/utils/request'

// 网站设置相关接口
export interface WebsiteSettings {
  siteName: string
  slogan: string
  contactPhone: string
  contactEmail: string
  logo: any[]
  logoUrl: string
  icp: string
  title: string
  keywords: string
  description: string
  baiduAnalytics: string
}

export const getWebsiteSettings = () => {
  return request<WebsiteSettings>({
    url: '/settings/website',
    method: 'GET'
  })
}

export const updateWebsiteSettings = (data: WebsiteSettings) => {
  return request({
    url: '/settings/website',
    method: 'POST',
    data
  })
}

// 支付设置相关接口
export interface PaymentSettings {
  // 微信支付
  wechatEnabled: boolean
  wechatMchId: string
  wechatAppId: string
  wechatApiKey: string
  
  // 支付宝
  alipayEnabled: boolean
  alipayAppId: string
  alipayPrivateKey: string
  alipayPublicKey: string
  
  // 银联支付
  unionpayEnabled: boolean
  unionpayMchId: string
  
  // 订单设置
  orderTimeout: number
  autoConfirmDays: number
  refundDays: number
}

export const getPaymentSettings = () => {
  return request<PaymentSettings>({
    url: '/settings/payment',
    method: 'GET'
  })
}

export const updatePaymentSettings = (data: PaymentSettings) => {
  return request({
    url: '/settings/payment',
    method: 'POST',
    data
  })
}

// 通知设置相关接口
export interface NotificationSettings {
  // 邮件设置
  emailEnabled: boolean
  smtpHost: string
  smtpPort: number
  smtpEncryption: 'none' | 'ssl' | 'tls'
  smtpEmail: string
  smtpName: string
  smtpUsername: string
  smtpPassword: string
  
  // 短信设置
  smsEnabled: boolean
  smsProvider: 'aliyun' | 'tencent' | 'netease'
  
  // 阿里云短信
  aliyunAccessKeyId: string
  aliyunAccessKeySecret: string
  aliyunSignName: string
  
  // 腾讯云短信
  tencentSecretId: string
  tencentSecretKey: string
  tencentSdkAppId: string
  tencentSignName: string
}

export interface NotificationTemplate {
  id: string
  name: string
  emailEnabled: boolean
  emailSubject: string
  emailContent: string
  smsEnabled: boolean
  smsContent: string
  smsTemplateId: string
}

export const getNotificationSettings = () => {
  return request<NotificationSettings>({
    url: '/settings/notification',
    method: 'GET'
  })
}

export const updateNotificationSettings = (data: NotificationSettings) => {
  return request({
    url: '/settings/notification',
    method: 'POST',
    data
  })
}

export const getNotificationTemplates = () => {
  return request<NotificationTemplate[]>({
    url: '/settings/notification/templates',
    method: 'GET'
  })
}

export const updateNotificationTemplates = (data: NotificationTemplate[]) => {
  return request({
    url: '/settings/notification/templates',
    method: 'POST',
    data
  })
}

export const sendTestEmail = (data: { email: string; [key: string]: any }) => {
  return request({
    url: '/settings/notification/test-email',
    method: 'POST',
    data
  })
}

export const sendTestSms = (data: { phone: string; [key: string]: any }) => {
  return request({
    url: '/settings/notification/test-sms',
    method: 'POST',
    data
  })
}

// 备份设置相关接口
export interface BackupConfig {
  autoBackup: boolean
  backupFrequency: 'daily' | 'weekly' | 'monthly'
  keepBackups: number
  backupContent: string[]
  backupStorage: 'local' | 'cloud'
  cloudProvider: 'aliyun' | 'tencent' | 'qiniu'
  cloudAccessKey: string
  cloudSecretKey: string
  cloudBucket: string
  cloudRegion: string
}

export interface BackupItem {
  id: string
  name: string
  type: 'auto' | 'manual'
  content: string[]
  size: number
  storage: 'local' | 'cloud'
  createdAt: string
  description?: string
}

export interface BackupListParams {
  page: number
  pageSize: number
}

export interface BackupListResponse {
  items: BackupItem[]
  total: number
}

export interface CreateBackupParams {
  content: string[]
  description?: string
  type: 'manual' | 'auto'
}

export const getBackupConfig = () => {
  return request<BackupConfig>({
    url: '/settings/backup-config',
    method: 'GET'
  })
}

export const updateBackupConfig = (data: BackupConfig) => {
  return request({
    url: '/settings/backup-config',
    method: 'POST',
    data
  })
}

export const getBackupList = (params: BackupListParams) => {
  return request<BackupListResponse>({
    url: '/backups',
    method: 'GET',
    params
  })
}

export const createBackup = (data: CreateBackupParams) => {
  return request({
    url: '/backups',
    method: 'POST',
    data
  })
}

export const restoreBackup = (id: string) => {
  return request({
    url: `/backups/${id}/restore`,
    method: 'POST'
  })
}

export const deleteBackup = (id: string) => {
  return request({
    url: `/backups/${id}`,
    method: 'DELETE'
  })
} 